<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>NumCpp: InterfaceWithOpenCV.cpp</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="NumCppLogoDoxygen.png"/></td>
  <td id="projectalign" style="padding-left: 0.5em;">
   <div id="projectname">NumCpp
   &#160;<span id="projectnumber">2.1.0</span>
   </div>
   <div id="projectbrief">A C++ implementation of the Python Numpy library</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
  initMenu('',true,false,'search.php','Search');
  $(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('_interface_with_open_c_v_8cpp-example.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">InterfaceWithOpenCV.cpp</div>  </div>
</div><!--header-->
<div class="contents">
<p>Example for interfaceing with OpenCV Mat</p>
<div class="fragment"><div class="line"><span class="preprocessor">#include &quot;<a class="code" href="_num_cpp_8hpp.html">NumCpp.hpp</a>&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &quot;opencv2/core/core.hpp&quot;</span></div>
<div class="line"><span class="preprocessor">#include &quot;opencv2/highgui/highgui.hpp&quot;</span></div>
<div class="line"> </div>
<div class="line"><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;numeric&gt;</span></div>
<div class="line"> </div>
<div class="line">constexpr <a class="code" href="namespacenc.html#af0f49663fb63332596e2e6327009d581">nc::uint32</a> NUM_ROWS = 512;</div>
<div class="line">constexpr <a class="code" href="namespacenc.html#af0f49663fb63332596e2e6327009d581">nc::uint32</a> NUM_COLS = 512;</div>
<div class="line"> </div>
<div class="line"><span class="keywordtype">int</span> main()</div>
<div class="line">{</div>
<div class="line">    <span class="comment">// create a ramp image with NumCpp</span></div>
<div class="line">    constexpr <span class="keyword">auto</span> numHalfCols = NUM_COLS / 2; <span class="comment">// integer division</span></div>
<div class="line">    <span class="keyword">auto</span> ncArray = <a name="_a0"></a><a class="code" href="classnc_1_1_nd_array.html">nc::NdArray&lt;nc::uint8&gt;</a>(NUM_ROWS, NUM_COLS);</div>
<div class="line">    <span class="keywordflow">for</span> (<a class="code" href="namespacenc.html#af0f49663fb63332596e2e6327009d581">nc::uint32</a> row = 0; row &lt; ncArray.numRows(); ++row)</div>
<div class="line">    {</div>
<div class="line">        <span class="keyword">auto</span> begin = ncArray.begin(row);</div>
<div class="line">        std::iota(begin, begin + numHalfCols, <a class="code" href="namespacenc.html#a9ba5a0aa26753a185985b8273fb9062d">nc::uint8</a>{0});</div>
<div class="line"> </div>
<div class="line">        <span class="keyword">auto</span> rbegin = ncArray.rbegin(row);</div>
<div class="line">        std::iota(rbegin, rbegin + numHalfCols, <a class="code" href="namespacenc.html#a9ba5a0aa26753a185985b8273fb9062d">nc::uint8</a>{0});</div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// convert to OpenCV Mat</span></div>
<div class="line">    <span class="keyword">auto</span> cvArray = cv::Mat(ncArray.numRows(), ncArray.numCols(), CV_8SC1, ncArray.data());</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// display the OpenCV Mat</span></div>
<div class="line">    cv::namedWindow(<span class="stringliteral">&quot;Display window&quot;</span>, cv::WINDOW_AUTOSIZE); <span class="comment">// Create a window for display.</span></div>
<div class="line">    cv::imshow(<span class="stringliteral">&quot;Display window&quot;</span>, cvArray); <span class="comment">// Show our image inside it.</span></div>
<div class="line">    cv::waitKey(0); <span class="comment">// Wait for a keystroke in the window</span></div>
<div class="line"> </div>
<div class="line">    <span class="comment">// tranpose the Mat with OpenCV</span></div>
<div class="line">    <span class="keyword">auto</span> transposedCvArray = cv::Mat(cvArray.cols, cvArray.rows, CV_8SC1);</div>
<div class="line">    <a name="a1"></a><a class="code" href="namespacenc.html#aa6c78ac10e4c3aa446716f80aa1a72ca">cv::transpose</a>(cvArray, transposedCvArray);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// display the transposed Mat</span></div>
<div class="line">    cv::namedWindow(<span class="stringliteral">&quot;Display window&quot;</span>, cv::WINDOW_AUTOSIZE); <span class="comment">// Create a window for display.</span></div>
<div class="line">    cv::imshow(<span class="stringliteral">&quot;Display window&quot;</span>, transposedCvArray); <span class="comment">// Show our image inside it.</span></div>
<div class="line">    cv::waitKey(0); <span class="comment">// Wait for a keystroke in the window</span></div>
<div class="line"> </div>
<div class="line">    <span class="comment">// convert the transposed OpenCV Mat to a NumCpp array</span></div>
<div class="line">    <span class="keyword">auto</span> transposedNcArray = <a class="code" href="classnc_1_1_nd_array.html">nc::NdArray&lt;nc::uint8&gt;</a>(transposedCvArray.data, transposedCvArray.rows, transposedCvArray.cols);</div>
<div class="line"> </div>
<div class="line">    <span class="comment">// make sure the two transposed arrays are the same</span></div>
<div class="line">    <span class="keywordflow">if</span> (<a name="a2"></a><a class="code" href="namespacenc.html#a0e8c1396cc01ccd9ec8ba549b6347e21">nc::array_equal</a>(transposedNcArray, ncArray.transpose()))</div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;Arrays are equal.\n&quot;</span>;</div>
<div class="line">    }</div>
<div class="line">    <span class="keywordflow">else</span></div>
<div class="line">    {</div>
<div class="line">        std::cout &lt;&lt; <span class="stringliteral">&quot;Arrays are not equal.\n&quot;</span>;</div>
<div class="line">    }</div>
<div class="line"> </div>
<div class="line">    <span class="keywordflow">return</span> 0;</div>
<div class="line">}</div>
</div><!-- fragment --> </div><!-- contents -->
</div><!-- doc-content -->
<div class="ttc" id="anamespacenc_html_a9ba5a0aa26753a185985b8273fb9062d"><div class="ttname"><a href="namespacenc.html#a9ba5a0aa26753a185985b8273fb9062d">nc::uint8</a></div><div class="ttdeci">std::uint8_t uint8</div><div class="ttdef"><b>Definition:</b> Types.hpp:43</div></div>
<div class="ttc" id="a_num_cpp_8hpp_html"><div class="ttname"><a href="_num_cpp_8hpp.html">NumCpp.hpp</a></div></div>
<div class="ttc" id="aclassnc_1_1_nd_array_html"><div class="ttname"><a href="classnc_1_1_nd_array.html">nc::NdArray</a></div><div class="ttdoc">Holds 1D and 2D arrays, the main work horse of the NumCpp library.</div><div class="ttdef"><b>Definition:</b> NdArrayCore.hpp:75</div></div>
<div class="ttc" id="anamespacenc_html_af0f49663fb63332596e2e6327009d581"><div class="ttname"><a href="namespacenc.html#af0f49663fb63332596e2e6327009d581">nc::uint32</a></div><div class="ttdeci">std::uint32_t uint32</div><div class="ttdef"><b>Definition:</b> Types.hpp:41</div></div>
<div class="ttc" id="anamespacenc_html_a0e8c1396cc01ccd9ec8ba549b6347e21"><div class="ttname"><a href="namespacenc.html#a0e8c1396cc01ccd9ec8ba549b6347e21">nc::array_equal</a></div><div class="ttdeci">bool array_equal(const NdArray&lt; dtype &gt; &amp;inArray1, const NdArray&lt; dtype &gt; &amp;inArray2) noexcept</div><div class="ttdef"><b>Definition:</b> array_equal.hpp:49</div></div>
<div class="ttc" id="anamespacenc_html_aa6c78ac10e4c3aa446716f80aa1a72ca"><div class="ttname"><a href="namespacenc.html#aa6c78ac10e4c3aa446716f80aa1a72ca">nc::transpose</a></div><div class="ttdeci">NdArray&lt; dtype &gt; transpose(const NdArray&lt; dtype &gt; &amp;inArray)</div><div class="ttdef"><b>Definition:</b> transpose.hpp:48</div></div>
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.17 </li>
  </ul>
</div>
</body>
</html>
